package ce.com.cenewbluesdk.connect;

/**
 * Created by Administrator on 2016/11/9 0009.
 */
public class ReconnectModeA implements ReconnectMode {

    private final int defTempConnectTime = 0;

    private int tempConnectTime = defTempConnectTime;

    /**
     * 回连次数
     */
    private int connectTimes = 0;
    private long[] interval = new long[]{2000, 5000, 10000, 30000};

    @Override
    public int getConnectTimes() {
        return connectTimes;
    }

    @Override
    public long getConnectIntervalTime() {
        int index = connectTimes / 10;
        if (index > 3) {
            index = 3;
        }
        return interval[index];
    }

    @Override
    public void clearConnectTimes() {
        connectTimes = 0;
    }

    @Override
    public void addConnectTimes() {
        connectTimes++;
    }

    @Override
    public boolean needTempConnect() {
        tempConnectTime--;
        return tempConnectTime >= 0;
    }

    @Override
    public void resetTempConnect() {
        tempConnectTime = defTempConnectTime;

    }

    @Override
    public void clearTempConnect() {
        tempConnectTime=-1;
    }
}
